
var Helper = {
    formatDate(days = 0) {
        var date = new Date()
        if (days > 0) {
            date.setDate(date.getDate() + days)
        }

        var year = date.getFullYear();
        var month = ("0" + (date.getMonth() + 1)).slice(-2);
        var sdate = ("0" + date.getDate()).slice(-2);
        var hour = ("0" + date.getHours()).slice(-2);
        var minute = ("0" + date.getMinutes()).slice(-2);
        var second = ("0" + date.getSeconds()).slice(-2);
        return year + "-" + month + "-" + sdate + " " + hour + ":" + minute + ":" + second;
    },
    format(time) {
        var date = new Date(time * 1000)
        var year = date.getFullYear();
        var month = ("0" + (date.getMonth() + 1)).slice(-2);
        var sdate = ("0" + date.getDate()).slice(-2);
        var hour = ("0" + date.getHours()).slice(-2);
        var minute = ("0" + date.getMinutes()).slice(-2);
        var second = ("0" + date.getSeconds()).slice(-2);
        return year + "-" + month + "-" + sdate ;
    },
    strReplaceStart(str) {
        return str.substring(0,7) + "****"
    },
    open(url,params =null) {
        if (params) {
            if (url.indexOf("?") === -1) {
                url += '?'
            } else {
                if (url.slice(-1) !== '&') {
                    url += '&'
                }
            }
            Object.keys(params).forEach((key)=>{
                url += key + "=" + params[key] + "&"
            })
            url = url.slice(0,url.length - 1)
        }
        console.log(url)
        layer.open({
            type:2,
            title:false,
            area:['95%','95%'],
            content:url
        })
    },
    close(index = null) {
        if (index) {
            layer.close(index)
        } else {
            layer.closeAll()
        }
    },
    getPar(par){
        //获取当前URL
        var local_url = document.location.href;
        //获取要取得的get参数位置
        var get = local_url.indexOf(par +"=");
        if(get === -1){
            return false;
        }
        //截取字符串
        var get_par = local_url.slice(par.length + get + 1);
        //判断截取后的字符串是否还有其他get参数
        var nextPar = get_par.indexOf("&");
        if(nextPar !== -1){
            get_par = get_par.slice(0, nextPar);
        }
        return get_par;
    },
    get(key) {
        return sessionStorage.getItem(key)
    },
    set(key,value) {
        sessionStorage.setItem(key,value)
    },
    clear(key = null) {
        if (key) {
            sessionStorage.removeItem(key)
        } else {
            sessionStorage.clear()
        }
    },

}